//
//  HcardHttpmanager.m
//  CheekiOS
//
//  Created by mac on 2017/5/11.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HcardHttpmanager.h"
#import <AVFoundation/AVFoundation.h>
#import <MobileCoreServices/MobileCoreServices.h>
@implementation HcardHttpmanager
/**
 *  闪约宝贝列表
 *
 *  @param uid          uid
 *  @param lon          经度
 *  @param lat          纬度
 *  @param hometown     所在城市
 *  @param sex          性别 0女 1男 2全部
 *  @param maxAge       最大年龄
 *  @param minAge       最小年龄
 *  @param distance     距离
 *  @param videoStatus  是否视频认证
 *  @param page         page
 *  @param sort         状态
 *  @param active       活跃
 *  @param successBlock 成功返回
 */
+ (void)sListWithUid:(NSString *)uid
                 lon:(NSNumber *)lon
                 lat:(NSNumber *)lat
            hometown:(NSString *)hometown
                 sex:(NSString *)sex
              maxAge:(NSString *)maxAge
              minAge:(NSString *)minAge
            disatnce:(NSString *)distance
         videoStatus:(NSNumber *)videoStatus
                page:(NSNumber *)page
                sort:(NSString *)sort
            withRows:(NSNumber *)rows
              active:(NSString *)active
        successBlock:(void (^)(BOOL, NSDictionary *))successBlock {
    NSMutableDictionary *params = @{@"uid":[HQHttpManager getUserId],@"page":page}.mutableCopy;
    if (lon) {
        [params setObject:lon forKey:@"lon"];
    }
    if (lat) {
        [params setObject:lat forKey:@"lat"];
    }
    if (hometown) {
        [params setObject:hometown forKey:@"hometown"];
    }
    if (sex) {
        [params setObject:sex forKey:@"sex"];
    }
    if (maxAge) {
        [params setObject:maxAge forKey:@"maxAge"];
    }
    if (minAge) {
        [params setObject:minAge forKey:@"minAge"];
    }
    if (distance) {
        [params setObject:distance forKey:@"distance"];
    }
    if (videoStatus) {
        [params setObject:videoStatus forKey:@"videoStatus"];
    }
    if (sort) {
        [params setObject:sort forKey:@"sort"];
    }
    if(rows){
        [params setObject:rows forKey:@"rows"];
    }
    if (active) {
        [params setObject:active forKey:@"active"];
    }
//    NSLog(@"params=%@",params);
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"sList") parameters:params type:HttpRequestTypePost success:^(id response) {

        if (response) {
            NSNumber *ok = response[@"ok"];
            if (![ok isEqual:@0]) {
                NSLog(@"闪约宝贝列表接口调用成功");
                successBlock (YES,@{@"res":response[@"res"]});
                NSLog(@"sList=%@",[response description]);

            } else {
                NSLog(@"闪约宝贝列表错误返回:%@",response[@"message"]);
                [[DMCAlertCenter defaultCenter] postAlertWithMessage:response[@"message"]];
                successBlock (NO,nil);
            }
        }
    } failure:^(NSError *err) {
        NSLog(@"闪约宝贝列表错误返回:%@",err.description);
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接失败"];
        successBlock (NO,nil);
    }];
}

/**
 我不/喜欢他/她
 @param wid 被不/喜欢 id || uid 用户ID
 @param state 1喜欢 0不喜欢
 */
+(void)likeHerOrHimWithWid:(NSString *)wid
                     state:(NSString *)state
              successBlock:(void (^)(BOOL, NSDictionary *))successBlock
                   failure:(void (^)(NSError * error))failure{
    NSDictionary *dic = @{
                          @"uid":[HQHttpManager getUserId],
                          @"wid":wid,
                          @"state":state
                          };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"woo") parameters:dic type:HttpRequestTypePost success:^(id result) {
        NSLog(@"woores================%@",result);
        NSNumber *ok = result[@"ok"];
        if (![ok isEqual:@0]) {
            successBlock(YES,result[@"ok"]);
        } else {

            [[DMCAlertCenter defaultCenter] postAlertWithMessage:result[@"message"]];
            successBlock (NO,nil);

        }
    } failure:^(NSError *error) {
        NSLog(@"wooresfailure");
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接失败"];
    }];
}

/**
 *  	申请添加好友
 */
+ (void)helloWithUid:(NSString *)uid wid:(NSString *)wid mobile:(NSString *)mobile successBlock:(void (^)(BOOL, NSDictionary *))successBlock {
    NSDictionary *params = @{};
    if (wid) {
        params = @{@"uid":uid,@"wid":wid};
    }
    if (mobile) {
        params = @{@"uid":uid,@"mobile":mobile};
    }
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"hello")
                                parameters:params
                                      type:HttpRequestTypePost
                                   success:^(id response){
         if (response) {
             NSLog(@"res%@",response);
             NSNumber *ok = response[@"ok"];
             if (![ok isEqual:@0]) {
                 NSLog(@"申请好友接口调用成功");
                 successBlock (YES,@{@"res":response[@"code"]});
             } else {
                 NSLog(@"申请好友错误返回:%@",response[@"message"]);
                 [[DMCAlertCenter defaultCenter] postAlertWithMessage:response[@"message"]];
                 successBlock (NO,nil);
             }
         }
     }
                    failure:^(NSError *err)
     {
         NSLog(@"申请好友错误返回:%@",err.description);
         [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接失败"];
         successBlock (NO,nil);
     }];
}


/**
 陌生人详细资料
 @param uid 陌生人ID
 @param myId 用户id
 */
+ (void)sInfoWithUid:(NSString *)uid
                myId:(NSString *)myId
        successBlock:(void(^)(BOOL isSuccess, NSDictionary *resultDic))successBlock{
    NSDictionary *params = @{@"uid":uid,@"myId":myId};
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"sInfo")
                                parameters:params
                                      type:HttpRequestTypePost
                                   success:^(id response) {
                                       if (response) {
                                           NSLog(@"res%@",response);
                                           NSNumber *ok = response[@"ok"];
                                           if (![ok isEqual:@0]) {
                                               NSLog(@"闪约宝贝详情接口调用成功");
                                               successBlock (YES,response[@"res"]);
                                           } else {
                                               NSLog(@"闪约宝贝详情错误返回:%@",response[@"message"]);
                                               [[DMCAlertCenter defaultCenter] postAlertWithMessage:response[@"message"]];
                                               successBlock (NO,nil);
                                           }
                                       }

    } failure:^(NSError *err) {
        NSLog(@"闪约宝贝详情错误返回:%@",err.description);
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接失败"];
        successBlock (NO,nil);

    }];
  
}


/**
 @param wid 要拉黑的好友id uid 我的用户id
 */
+(void)blackFriendWithWid:(NSString *)wid
                  Success:(void (^)(id result))success
                  failure:(void (^)(NSError * error))failure{

    NSDictionary *dict =@{
                          @"uid":[HQHttpManager getUserId],
                          @"wid":wid
                          };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/blackFriend") parameters:dict type:HttpRequestTypePost success:^(id result) {
        NSLog(@"%@",result);
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
                [SVProgressHUD showSuccessWithStatus:@"拉黑成功"];
            }
            else{
                success(nil);
                [SVProgressHUD showErrorWithStatus:@"拉黑失败"];
            }
        }
    } failure:^(NSError *error) {
        failure(error);
        [SVProgressHUD showErrorWithStatus:@"拉黑失败"];
    }];
    


}


/**
 发布朋友圈


 @param type 类型
 @param content 文字内容
 @param videoStr 视频
 @param imgStr 照片
 @param locStr 位置
 @param seeType 让谁看
 @param somebodyUid 一些人的ID
 @param remindUid 提醒谁看
 @param success 回调
 @param failure 错误信息
 */
+(void)publishFriendCircleWithType:(addCircleType)type
                       WithContent:(NSString *)content
                         WithVideo:(NSString *)videoStr
                           WithImg:(NSString *)imgStr
                      WithLocation:(NSString*)locStr
                       WithSeetype:(NSInteger)seeType
                      WithSomebody:(NSString *)somebodyUid
                        WithRemind:(NSString *)remindUid
                           Success:(void (^)(id result))success
                           failure:(void (^)(NSError * error))failure{
    NSMutableDictionary *paramD = [NSMutableDictionary dictionary];
    [paramD setObject:[HQHttpManager getUserId] forKey:@"uid"];
    [paramD setObject:@(type) forKey:@"type"];
    content.length!=0?[paramD setObject:content forKey:@"content"]:nil;
    videoStr.length!=0?[paramD setObject:videoStr forKey:@"video"]:nil;
    imgStr.length!=0?[paramD setObject:imgStr forKey:@"img"]:nil;
    locStr.length!=0?[paramD setObject:locStr forKey:@"location"]:nil;
    content.length!=0?[paramD setObject:content forKey:@"content"]:nil;
    somebodyUid.length!=0?[paramD setObject:somebodyUid forKey:@"somebody"]:nil;
    remindUid.length!=0?[paramD setObject:remindUid forKey:@"remind"]:nil;
    [paramD setObject:@(seeType) forKey:@"seeType"];
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/active/addCircle") parameters:paramD type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
            }
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
    
}


/**
 上传多张图片

 @param imageArr 图片数组
 @param belong 成员
 @param ToAlblum 类型
 @param AlbumId 相册ID
 @param success 回调
 @param failure 错误信息
 */
+(void)upLoadPhotosWithFileArr:(NSArray*)imageArr
                    WithBelong:(NSString*)belong
                  WithToAublum:(ToAublum)ToAlblum
                   WithAlbumId:(NSString*)AlbumId
                       success:(void (^)(id sucess))success
                       failure:(void (^)(NSError * error))failure{
    NSMutableArray *arrMS = [NSMutableArray array];
    [arrMS removeAllObjects];
    for(int i= 0 ;i<imageArr.count;i++){
        UIImage *imag = imageArr[i];
        NSData *imageData = UIImageJPEGRepresentation(imag, 0.5);
        NSDictionary *dict = [NSDictionary dictionary];
        if(ToAlblum == KToAublumNO){
            dict = @{
                     @"file":imageData,
                     @"belong":belong,
                     @"toAlbum":@(ToAlblum)
                     };
        }
        else{
            dict = @{
                     @"file":imageData,
                     @"belong":belong,
                     @"toAlbum":@(ToAlblum),
                     @"albumId":AlbumId
                     };
        }
        [HcardManagerTool uploadImageWithImage:imag Url:HttpUrlStringS(@"/common/uploadFile") Dictionary:dict success:^(id result) {
            if(result){
                [arrMS addObject:result[@"res"]];
                if(arrMS.count==imageArr.count){
                    success(arrMS);
                }
            }
        } failure:^(NSError * error) {
            failure(error);
        }];
    }
}

+(void)upLoadPhotosWithFile:(UIImage*)image
                 WithBelong:(NSString*)belong
               WithToAublum:(ToAublum)ToAlblum
                WithAlbumId:(NSString*)AlbumId
                    success:(void (^)(id sucess))success
                    failure:(void (^)(NSError * error))failure{
   

    UIImage *image1=[HcardHttpmanager thumbnailWithImageWithoutScale:image size:CGSizeMake(200, 200)];
    NSData *imageData = UIImageJPEGRepresentation(                                                                                                                                                                                                     image1,0.5);
    NSDictionary *dict = [NSDictionary dictionary];
    if(ToAlblum == KToAublumNO){
        dict = @{
                 @"file":imageData,
                 @"belong":belong,
                 @"toAlbum":@(ToAlblum)
                 };
    }
    else{
        dict = @{
                 @"file":imageData,
                 @"belong":belong,
                 @"toAlbum":@(ToAlblum),
                 @"albumId":AlbumId
                 };
    }
    [HcardManagerTool uploadImageWithImage:image Url:HttpUrlStringS(@"/common/uploadFile") Dictionary:dict success:^(id result) {
        if(result){
            if([result[@"code"]isEqualToString:@"ok"])
                success(result[@"res"]);
        }
    } failure:^(NSError * error) {
        failure(error);
    }];
}

//保持原始图片的长宽比，生成需要尺寸的图片：
+ (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
    UIImage *newimage;
    if (nil == image) {
        newimage = nil;
    }
    else{
        CGSize oldsize = image.size;
        CGRect rect;
        if (asize.width/asize.height > oldsize.width/oldsize.height) {
            rect.size.width = asize.height*oldsize.width/oldsize.height;
            rect.size.height = asize.height;
            rect.origin.x = (asize.width - rect.size.width)/2;
            rect.origin.y = 0;
        }
        else{
            rect.size.width = asize.width;
            rect.size.height = asize.width*oldsize.height/oldsize.width;
            rect.origin.x = 0;
            rect.origin.y = (asize.height - rect.size.height)/2;
        }
        UIGraphicsBeginImageContext(asize);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
        UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
        [image drawInRect:rect];
        newimage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    return newimage;
}

/**
 发布视频转码

 @param videoURL 连接
 @param time 时间
 @return 返回
 */
+ (UIImage*)thumbnailImageForVideo:(NSURL *)videoURL
                            atTime:(NSTimeInterval)time{

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    NSParameterAssert(asset);
    AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
    assetImageGenerator.appliesPreferredTrackTransform = YES;
    assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
    
    CGImageRef thumbnailImageRef = NULL;
    CFTimeInterval thumbnailImageTime = time;
    NSError *thumbnailImageGenerationError = nil;
    thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];
    
    if(!thumbnailImageRef)
        NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);
    
    UIImage*thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage: thumbnailImageRef] : nil;
    
    return thumbnailImage;
}


#pragma mark 图片上传接口
+ (void)uploadImageWithImage:(UIImage *)img
                   imgBelong:(NSString *)imgBelong
                successBlock:(void (^)(BOOL, NSDictionary *))successBlock {
    NSDictionary *params = @{@"belong":imgBelong,@"toAlbum":@"0"};
    NSData *imageData = UIImageJPEGRepresentation(img, 1);
    float length = [imageData length]/1000;
    float scale = 0.0f;
    if (length > 100) {
        scale = 100.0f /length;
    }else{
        scale = 1.0f;
    }
    
    NSData *fData = UIImageJPEGRepresentation(img, scale);
    NSURL* baseURL = [NSURL URLWithString:HttpUrlString];
    //获得请求管理者
    NSDictionary *newParams = [CodingTools signDataString:params];
    
    AFHTTPSessionManager* mgr = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
    
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json",@"text/javascript", @"text/plain", nil];
    [mgr     POST:@"common/uploadFile"
       parameters:newParams
constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData)
     {
         [formData appendPartWithFileData:fData name:@"file" fileName:@"image" mimeType:@"image/jpeg"];
     }
         progress:^(NSProgress * _Nonnull uploadProgress)
     {
         
     }
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject)
     {
         NSString *returnCode = [NSString stringWithFormat:@"%@",responseObject[@"code"]];
         if ([returnCode isEqualToString:@"ok"]) {
             NSLog(@"图片上传：%@",responseObject);
             successBlock(YES,responseObject);
         }else {
             NSLog(@"图片上传错误返回%@",responseObject[@"message"]);
             successBlock(NO,nil);
         }
         
     }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
     {
         NSLog(@"图片上传失败%@",error.description);
         if (successBlock) {
             successBlock(NO,nil);
         }
     }];
    
    
}


/**
 上传视频转码

 @param videoURL 内容
 @param belong 属性
 @param sucess 回调
 @param failure 错误
 @param progress 进展
 */
+ (void)upLoadVideoVideoPath:(NSURL *)videoURL
                  WithBelong:(NSString *)belong
               uploadSuccess:(void (^)(id sucess))sucess
               uploadFailure:(void (^)(NSError * failure))failure
                    progress:(void (^)(NSProgress * progress))progress{
    //此处为对视频进行转码并且压缩为，最终输出为MP4的格式
    //输出后将文件保存到了/Library/Caches/文件夹内
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];
    NSDateFormatter* formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyyMMddHHmmss"];
    NSString *mp4Path = [NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/output%@.mp4", [formater stringFromDate:[NSDate date]]];
    exportSession.outputURL = [NSURL fileURLWithPath: mp4Path];
    exportSession.outputFileType = AVFileTypeMPEG4;
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        switch ([exportSession status]) {
            case AVAssetExportSessionStatusFailed:
            {
                [SVProgressHUD showErrorWithStatus:@"上传失败"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
                break;
            }
            case AVAssetExportSessionStatusCancelled:
                [SVProgressHUD showErrorWithStatus:@"上传失败"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
                break;
            case AVAssetExportSessionStatusCompleted:
            {
                NSData *videoData = [NSData dataWithContentsOfFile:mp4Path];
                NSDictionary *dict =@{
                                      @"file":videoData,
                                      @"belong":belong,
                                      @"toAlbum":@(0)
                                      };
                [HcardManagerTool upLoadVideoWithOption:dict withInferface:HttpUrlStringS(@"/common/uploadFile") videoPath:mp4Path uploadSuccess:^(id result) {
                    if(result){
                        if([result[@"code"]isEqualToString:@"ok"])
                            sucess(result[@"res"]);
                        else [[DMCAlertCenter defaultCenter] postAlertWithMessage:result[@"message"]];
                    }
                } uploadFailure:^(NSError * error) {
                    failure(error);
                } progress:^(NSProgress * progressA) {
                    progress(progressA);
                }];
                break ;
            }
            default:
                break;
        }
    }];
    
}

/**
 获取钻石

 @param success 回调
 @param failure 错误信息
 */
+(void)getuserInfocharmsuccess:(void (^)(id))success failure:(void (^)(NSError *))failure{
 
    NSDictionary *dict = @{
                           @"uid":[HQHttpManager getUserId]
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/userInfo2") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success([UserInfocharmModel mj_objectWithKeyValues: result[@"res"]]);
            }
        }
    } failure:^(NSError *error) {
        
    }];
    
}

+(void)inOutCharmWithCharm:(NSString *)charm
                  withCost:(NSString *)cost
                  withNote:(NSString *)note
                  withType:(inOutCharmType)inOutCharmType
               withTransNo:(NSString*)transNo
                withCharm1:(NSString *)charm1
           withfirstCharge:(NSString *)firstCharge
                   success:(void (^)(id result))success
                   failure:(void (^)(NSError * error))failure{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if (charm1.length > 0) {
        
        
        if (charm) {
            [dic setObject:charm forKey:@"charm"];
        }
        if (cost) {
            [dic setObject:cost forKey:@"cost"];
        }
        if (note) {
            [dic setObject:note forKey:@"note"];
        }
        if (inOutCharmType) {
            [dic setObject:@(inOutCharmType) forKey:@"type"];
        }
        if (transNo) {
            [dic setObject:transNo forKey:@"transNo"];
        }
        if (charm1) {
            [dic setObject:charm1 forKey:@"charm1"];
        }
        [dic setObject:[HQHttpManager getUserId] forKey:@"uid"];

   

    }else{
        
        if (charm) {
            [dic setObject:charm forKey:@"charm"];
        }
        if (cost) {
            [dic setObject:cost forKey:@"cost"];
        }
        if (note) {
            [dic setObject:note forKey:@"note"];
        }
        if (inOutCharmType) {
            [dic setObject:@(inOutCharmType) forKey:@"type"];
        }
        if (transNo) {
            [dic setObject:transNo forKey:@"transNo"];
        }
        if (firstCharge) {
            [dic setObject:firstCharge forKey:@"firstCharge"];
        }
        [dic setObject:[HQHttpManager getUserId] forKey:@"uid"];
  
    }
    
    
      [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/inOutCharm") parameters:dic type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
//                [SVProgressHUD showSuccessWithStatus:@"支付成功!"];
                success(result);
            }else{
                [SVProgressHUD showInfoWithStatus:result[@"message"]];
            }
        }
        
    } failure:^(NSError * error) {
        [SVProgressHUD showErrorWithStatus:@"支付失败"];
    }];

}


+(void)getMyGiftsWith:(giftType)type
              withLoc:(CLLocation*)loc
             withPage:(NSInteger)page
             withRows:(NSInteger)rows
              success:(void (^)(id result))success
              failure:(void (^)(NSError * error))failure{
    NSDictionary *dict= [NSDictionary dictionary];
    if(loc!=nil){
        dict = @{
                 @"uid":[HQHttpManager getUserId],
                 @"type":@(type),
                 @"page":@(page),
                 @"rows":@(rows),
                 @"lon":@(loc.coordinate.longitude),
                 @"lat":@(loc.coordinate.latitude)
                 };
    }else{
        dict = @{
                 @"uid":[HQHttpManager getUserId],
                 @"type":@(type),
                 @"page":@(page),
                 @"rows":@(rows)
                 };
    }
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/myGiftList") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if([result[@"code"] isEqualToString:@"ok"]){
            success([YD_myGiftModel mj_objectArrayWithKeyValuesArray:result[@"res"]]);
        }
    } failure:^(NSError * error) {
        failure(error);
    }];
    
}



//赠送礼物
+(void)giveGiftWithWid:(NSString*)wid
            WithGiftId:(NSString*)giftId
            WithStatus:(NSString *)status
             WithAskId:(NSString *)askId
               Success:(void (^)(id result))success
               failure:(void (^)(NSError * error))failure{

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:[HQHttpManager getUserId] forKey:@"uid"];
    if(wid){
        [dict setObject:wid forKey:@"wid"];
    }
    if(status){
        [dict setObject:status forKey:@"status"];
    }
    if(askId){
        [dict setObject:askId forKey:@"askId"];
    }
    if(giftId){
        [dict setObject:giftId forKey:@"giftId"];
    }
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/giveGift") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
            }else{
                [SVProgressHUD showErrorWithStatus:result[@"message"]];
            }
        }
        
    } failure:^(NSError *error) {
        failure(error);
        [SVProgressHUD showErrorWithStatus:@"赠送失败"];
    }];
    
    


}



//获取赠送时的礼物列表
+(void)getGiftListWithPage:(NSInteger)page
                  withRows:(NSInteger)row
                   Success:(void (^)(id result))success
                   failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"page":@(page),
                           @"rows":@(row)
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/giftList") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success([GiftgivingModel mj_objectArrayWithKeyValuesArray:result[@"res"]]);
            }
        }
    } failure:^(NSError *error) {
        
    }];
    
}
//获取问题列表

+(void)getAskListWith:(type)type
             withPage:(NSInteger)page
             withRows:(NSInteger)rows
              success:(void (^)(id result))success
              failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"uid":[HQHttpManager getUserId],
                           @"type":@(type),
                           @"page":@(page),
                           @"rows":@(rows)
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/askList") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if([result[@"code"] isEqualToString:@"ok"]){
            success([GiftAskinterViewModel  mj_objectArrayWithKeyValuesArray:result[@"res"]]);
        }
    } failure:^(NSError * error) {
        failure(error);
    }];
    
}
//送礼物之后 去留言
+(void)giftMsgWithUserGiftId:(NSString *)userGiftId
                     WithMsg:(NSString *)msg
                     Success:(void (^)(id result))success
                     failure:(void (^)(NSError * error))failure{
    
    NSDictionary *dict = @{
                           @"userGiftId":userGiftId,
                           @"msg":msg
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/giftMsg") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
            }else{
                [SVProgressHUD showErrorWithStatus:@"留言失败"];
            }
        }
    } failure:^(NSError * error) {
        [SVProgressHUD showErrorWithStatus:@"留言失败"];
    }];
    
}
//评论回复某个人

+(void)CommentreplyUid:(NSString *)Uid
               content:(NSString *)content
               replyId:(NSInteger )replyId
              circleId:(NSInteger )circleId
               trystId:(NSInteger )trystId
               Success:(void (^)(id result))success
               failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"uid":Uid,
                           @"content":content,
                           @"replyId":@(replyId),
                           @"circleId":@(circleId)
                           };
    NSLog(@"%@",dict);
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"active/addReply") parameters:dict type:HttpRequestTypePost success:^(id result) {
    if(success){
        NSLog(@"%@",success);
        if([result[@"code"] isEqualToString:@"ok"]){
            success(result);
        }else{
            [SVProgressHUD showErrorWithStatus:@"留言失败"];
        }
    }
} failure:^(NSError * error) {
    [SVProgressHUD showErrorWithStatus:@"留言失败"];
}];

}
//请求朋友圈回复数据内容

+(void)FriendNewContentUserId:(NSString *)userId
                 successBlock:(void(^)(BOOL isSuccess, NSDictionary *resultDic))successBlock
                      failure:(void (^)(NSError * error))failure;

{
    NSDictionary *dict = @{@"uid":userId};

    
    NSString *str = HttpUrlStringS(@"active/userCircle/");
    
    
    [HcardManagerTool requestWithURLString:str parameters:dict type:HttpRequestTypePost success:^(id result) {
        
//        NSLog(@"朋友圈最新消息列表======result%@",result);
        NSNumber *ok = result[@"ok"];
        if (![ok isEqual:@0]) {
            successBlock(YES,result);
        } else {
            
            [[DMCAlertCenter defaultCenter] postAlertWithMessage:result[@"message"]];
            successBlock (NO,nil);
            
        }
    } failure:^(NSError *error) {
        NSLog(@"wooresfailure");
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接失败"];
    }];


}
//请求朋友圈回复历史消息
+(void)FriendNewhistoryUserId:(NSString *)userId
                         page:(NSInteger )page
                         rows:(NSInteger )rows
                 successBlock:(void(^)(BOOL isSuccess, NSDictionary *resultDic))successBlock
                      failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{@"uid":userId,
                           @"page":@(page),
                           @"rows":@(rows)
                           };

    NSString *str = HttpUrlStringS(@"/active/userCircleList/");
    
    
    [HcardManagerTool requestWithURLString:str parameters:dict type:HttpRequestTypePost success:^(id result) {
        
        //        NSLog(@"请求朋友圈回复历史消息======result%@",result);
        NSNumber *ok = result[@"ok"];
        if (![ok isEqual:@0]) {
            successBlock(YES,result);
        } else {
            
            [[DMCAlertCenter defaultCenter] postAlertWithMessage:result[@"message"]];
            successBlock (NO,nil);
            
        }
    } failure:^(NSError *error) {
        NSLog(@"wooresfailure");
        [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接失败"];
    }];


}
//个人信息设置
+(void)MakePersionalInfoWithParam:(NSDictionary*)param
                          success:(void (^)(id sucess))success
                          failure:(void (^)(NSError * error))failure{
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/updateUser") parameters:param type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                [SVProgressHUD showSuccessWithStatus:@"设置成功"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [SVProgressHUD dismiss];
                });
                success(result);
            }
            else{
                [SVProgressHUD showErrorWithStatus:result[@"message"]];
            }
        }
    } failure:^(NSError * error ) {
        if (failure) {
            failure(error);
            [SVProgressHUD showErrorWithStatus:@"修改失败!"];
        }
    }];
}

//获取个人信息
+(void)getPersionalInfosuccess:(void (^)(id sucess))success
                       failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"uid":[HQHttpManager getUserId],
                           @"myId":[HQHttpManager getUserId]
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/sInfo") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
            }
        }
    } failure:^(NSError * error ) {
        if (failure) {
            failure(error);
        }
    }];
}

//获取个人信息 UserInfo
+(void)getPersionalUserInfosuccess:(void (^)(id sucess))success
                           failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"uid":[HQHttpManager getUserId],
                           @"myId":[HQHttpManager getUserId]
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/userInfo") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
            }
        }
    } failure:^(NSError * error ) {
        if (failure) {
            failure(error);
        }
    }];
    
}


//上传身份信息
+ (void)getUserCardValidateName:(NSString *)name
                      idcardnum:(NSString *)cardnum
                        success:(void (^)(id sucess))success
                        failure:(void (^)(NSError * error))failure{
    
    NSDictionary *dict = @{@"uid":[HQHttpManager getUserId],
                           @"cardName":name,
                           @"cardNo":cardnum
                           };
  [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/cardValidate1") parameters:dict type:HttpRequestTypePost success:^(id result) {
      if (success) {
          
              success(result);
          
          
      }
  } failure:^(NSError * error) {
      
  }];


}


+(void)getCharmDetailListWithType:(charmDetailListType)charmDetailListType
                         withPage:(NSInteger)page
                         withRows:(NSInteger)rows
                          success:(void (^)(id result))success
                          failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = [NSDictionary dictionary];
    switch (charmDetailListType) {
        case KCharmDetailListTypeAll:
            dict = @{
                     @"uid":[HQHttpManager getUserId],
                     @"page":@(page),
                     @"rows":@(rows)
                     };
            break;
        case KCharmDetailListTypeIncome:
            dict = @{
                     @"uid":[HQHttpManager getUserId],
                     @"type":@(KCharmDetailListTypeIncome),
                     @"page":@(page),
                     @"rows":@(rows)
                     };
            break;
        case KCharmDetailListTypeExpense:
            dict = @{
                     @"uid":[HQHttpManager getUserId],
                     @"type":@(KCharmDetailListTypeExpense),
                     @"page":@(page),
                     @"rows":@(rows)
                     };
            break;
    }
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/charmDetailList") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                [UserCharmDetailListModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
                    return @{
                             @"ID" : @"id",
                             };
                }];
                success([UserCharmDetailListModel mj_objectArrayWithKeyValuesArray:result[@"res"]]);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
    
}


+(void)applyForWithdrawingMoneyWithCost:(NSString *)cost
                            WithEndCost:(NSString *)endCost
                                WithZfb:(NSString*)zfb
                                Withcharm1:(NSString *)charm1

                                success:(void (^)(id result))success
                                failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"uid":[HQHttpManager getUserId],
                           @"cost":cost,
                           @"endCost":endCost,
                           @"charm1":charm1,
                           @"zfb":zfb
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/withdrawals") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                [SVProgressHUD showSuccessWithStatus:@"提现成功!"];
                success(result);
            }else{
                [SVProgressHUD showInfoWithStatus:result[@"message"]];
            }
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"提现失败!"];
    }];
}

+(void)getFeeSuccess:(void (^)(id result))success
             failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"key":@"fee",
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/getDictByKey") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result[@"res"]);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
    
}
+(void)getProfessionalSuccess:(void (^)(id result))success
                      failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"key":@"job",
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/getDictByKey") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result[@"res"]);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];

}
+(void)getFeecharm1ToCostSuccess:(void (^)(id))success
                         failure:(void (^)(NSError *))failure{
    NSDictionary *dict = @{
                           @"key":@"charm1ToCost",
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/getDictByKey") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result[@"res"]);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
}

+(void)getWithDrawHisWithPage:(NSInteger)page
                     withRows:(NSInteger)rows
                      success:(void (^)(id result))success
                      failure:(void (^)(NSError * error))failure{
    
    NSDictionary *dict = @{
                           @"uid":[HQHttpManager getUserId],
                           @"page":@(page),
                           @"rows":@(rows)
                           };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/withdrawalsList") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result[@"res"]);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
    
}

+(void)getUsercheckMobile:(NSString *)Mobile
                  success:(void (^)(id result))success
                  failure:(void (^)(NSError * error))failure{

    NSDictionary *dict = @{
                           @"mobile":Mobile
                           };
    
        [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/checkMobile") parameters:dict type:HttpRequestTypePost success:^(id result) {
            if(success){
                
                    success(result);
                
            }
            
        } failure:^(NSError *error) {
            
        }];


}


//获取处罚名单
+(void)getPunishmentListsWithPage:(NSInteger)page
                         withRows:(NSInteger)row
                          Success:(void (^)(id result))success
                          failure:(void (^)(NSError * error))failure{

    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/blackList") parameters:nil type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success([UserpunishmentListModel mj_objectArrayWithKeyValuesArray:result[@"res"]]);
            }
        }
    } failure:^(NSError *error) {
        
    }];

}

//删除照片
+(void)deletePhotoWithPhotoId:(NSUInteger)photoId
                      Success:(void (^)(id result))success
                      failure:(void (^)(NSError * error))failure{
    
    [SVProgressHUD showSuccessWithStatus:@"正在删除"];
    NSDictionary *dict = @{
                           @"photoId":@(photoId)
                           };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/active/delPhoto") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result);
                [SVProgressHUD showSuccessWithStatus:@"删除成功"];
            }
            else{
                success(nil);
                [SVProgressHUD showErrorWithStatus:@"删除失败"];
            }
        }
    } failure:^(NSError *error) {
        failure(error);
        [SVProgressHUD showErrorWithStatus:@"删除失败"];
    }];
    
}

+(void)getSkillsKindsSuccess:(void (^)(id sucess))success
                     failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = @{
                           @"key":@"skill"
                           };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/getDictByKey") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                success(result[@"res"]);
            }
        }
    } failure:^(NSError * error ) {
        if (failure) {
            failure(error);
        }
    }];
}


+(void)getCharm1ListWithUid:(NSString *)Uid
                   withPage:(NSInteger)page
                   withRows:(NSInteger)rows
                    success:(void (^)(id))success
                    failure:(void (^)(NSError *))failure{

    NSDictionary *dict = @{@"uid":[HQHttpManager getUserId],
                          @"page":@(page),
                          @"rows":@(rows),
                          };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/charm1List") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            if([result[@"code"] isEqualToString:@"ok"]){
                [UserCharm1ListModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
                    return @{
                             @"ID" : @"id",
                             };
                }];
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];

}

+(void)getTaskReceiveWithUid:(NSString *)Uid
                    WithPage:(NSInteger )page
                    WithRows:(NSInteger )rows
                     success:(void (^)(id result))success
                     failure:(void (^)(NSError * error))failure{
    
    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"uid":Uid,
             @"page":@(page),
             @"rows":@(rows)
             };
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/getTaskReceive") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
                [UserNewTaskModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
                    return @{
                             @"ID" : @"id",
                             };
                }];
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];

}


+ (void)getreceiveCharmWithtaskId:(NSString *)taskId
                          WithUid:(NSString *)uid
                        WithCharm:(NSString *)charm
                          success:(void (^)(id result))success
                          failure:(void (^)(NSError * error))failure{
    
    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"id":taskId,
             @"uid":uid,
             @"charm":charm
             };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/receiveCharm") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
    
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];


}



+ (void)getshareTaskWithTaskId:(NSString *)taskId
                       success:(void (^)(id result))success
                       failure:(void (^)(NSError * error))failure{

    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"id":taskId
             };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/shareTask") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
                
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
    
}


+ (void)getReportUid:(NSString *)Uid
           reportUid:(NSString *)reportUid
                 Img:(NSString *)Img
              reason:(NSString *)reason
             success:(void (^)(id result))success
             failure:(void (^)(NSError * error))failure{
    

    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"uid":Uid,
             @"reportUid":reportUid,
             @"img":Img,
             @"reason":reason
             };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/report") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
                
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];
}


+ (void)getStartpagesuccess:(void (^)(id result))success
                    failure:(void (^)(NSError * error))failure{

    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"common/startImg") parameters:nil type:HttpRequestTypePost success:^(id result) {
        
        if (success) {
            if ([result[@"code"] isEqualToString:@"ok"]) {
                success(result);
            }
        }
    
        
    } failure:^(NSError *error) {
        
    }];

}

+ (void)getFrienduserCircleEmpty:(NSString *)Uid
                         success:(void (^)(id result))success
                         failure:(void (^)(NSError * error))failure{
    
    
    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"uid":Uid};
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/active/userCircleEmpty") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
                
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];

}

+ (void)getFeedBackUid:(NSString *)uid
               content:(NSString *)content
               success:(void (^)(id result))success
               failure:(void (^)(NSError * error))failure{

    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"uid":uid,
             @"content":content
             };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/feedback") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
                
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];

    

}


+ (void)getCommonOpen:(NSString *)uid
              success:(void (^)(id result))success
              failure:(void (^)(NSError * error))failure{
    NSDictionary *dict = [NSDictionary dictionary];
    dict = @{@"uid":uid,
             };
    
    [HcardManagerTool requestWithURLString:HttpUrlStringS(@"/common/open") parameters:dict type:HttpRequestTypePost success:^(id result) {
        if(success){
            
            if([result[@"code"] isEqualToString:@"ok"]){
                
                success(result);
            }
        }
        
    } failure:^(NSError *error) {
        
    }];



}

@end
